package com.dongjiantong.app.controller.quarantine;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongjiantong.common.exceptions.HttpCode;
import com.dongjiantong.common.model.Response;
import com.dongjiantong.common.web.sso.LoginInfo;
import com.dongjiantong.common.web.util.UserUtil;
import com.dongjiantong.openplatform.annotations.OpenBean;
import com.dongjiantong.openplatform.annotations.OpenMethod;
import com.dongjiantong.quarantine.model.SupervisionContent;
import com.dongjiantong.quarantine.serviceImpl.SupervisionContentReadService;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;
import java.util.Map;

/**
 * Created by mz on 25/12/17.
 *
 */
@OpenBean
@Slf4j
public class SupervisionContentController {

    @Reference(version = "1.0.0")
    private SupervisionContentReadService supervisionContentReadService;

    @OpenMethod(
            key = "find.supervision.content.by.area.code",
            httpMethods = RequestMethod.GET
    )
    public Response<List<SupervisionContent>> findByArea(){

        LoginInfo loginInfo = UserUtil.getCurrentUser();
        try{
            Map<String , Object> map = Maps.newHashMap();
            map.put("areaCode","" +
                    (loginInfo.getProvinceId() > 10 ? loginInfo.getProvinceId() : "0" + loginInfo.getProvinceId()) +
                    (loginInfo.getCityId() > 10 ? loginInfo.getCityId() : "0" + loginInfo.getCityId()) + "00000000");
//                    (loginInfo.getRegionId() > 10 ? loginInfo.getRegionId() : "0" + loginInfo.getRegionId()) +
//                    (loginInfo.getStreetId() > 100 ? loginInfo.getStreetId() : (loginInfo.getStreetId() > 10 ? "0" + loginInfo.getStreetId() : "00" + loginInfo.getStreetId())) +
//                    (loginInfo.getVillageId() > 100 ? loginInfo.getVillageId() : (loginInfo.getVillageId() > 10 ? "0" + loginInfo.getVillageId() : "00" + loginInfo.getVillageId())));

            return Response.ok(supervisionContentReadService.findAll(map));
        }catch (Exception e){
            log.error(e.getMessage());
            return Response.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(),HttpCode.INTERNAL_SERVER_ERROR.getMessage());
        }
    }
}
